package com.example.springboot01.testScope;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author keyer
 * @Description : 从容器中拿到bean，然后调用其方法
 * Created by cyd on 2021-04-30 14:49:06
 */
@Slf4j
public class TestMain {
    public static void main(String[] args) {
        // 手动配置类，配置类用组件扫描器，将“com.example.springboot01.testScope”下的bean填入容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ScopeConfig.class);
        DemoSingleTonService demoSingleton1 = context.getBean(DemoSingleTonService.class);
        DemoSingleTonService demoSingleton2 = context.getBean(DemoSingleTonService.class);

        DemoPrototypeService prototype1 = context.getBean(DemoPrototypeService.class);
        DemoPrototypeService prototype2 = context.getBean(DemoPrototypeService.class);

        System.out.println(demoSingleton1 == demoSingleton2);
        System.out.println(prototype1 == prototype2);

        prototype1.print();
        prototype2.print();

        context.close();

    }
}
